//Created by Koza
//The world holds a 2D array of nodes
#pragma once

//Needs access to the objects and other members of the object.h
#include <assert.h>
#include "Objects.h"

enum Directions
{
	NORTH,
	SOUTH,
	EAST,
	WEST,
	NullDirection
};

#define WORLD_HEIGHT 10
#define WORLD_WIDTH  10

const int AmountWalls = 2;
const int MaxItems = 4;
const int PosMod = 18;

class Node
{
private:
	// n * n = Total walls
	// n used for for loops
	int				m_kiAmountWalls;
	int				m_kiMaxItems;

	//Used to determine if this node has been visited yet or not
	bool			m_bVisited;
	//Used to determine if a direction is available to generate in
	bool			m_bNorth;
	bool			m_bSouth;
	bool			m_bEast;
	bool			m_bWest;

	//Holds any object in the node
	BaseActivator**	m_clppMyObject;
	//Holds any walls inactive or active
	Brick**			m_clppMyWalls;

public:
	//Base Constructor/Deconstructor
	Node(){}
	~Node();

	//Refreshes/Rebuilds all the walls as default
	inline void Reset(){}

	//Called in constructor and reset
	void Init(int WorldX,int WorldY);

	//Returns the WallAmount = n
	// n * n used for for loops
	inline int getAmountWalls(){return m_kiAmountWalls;}

	//North South East West walls can all hold an item
	// this just returns 4 for our program
	inline int getMaxItems(){return m_kiMaxItems;}

	//Used to put bricks in the vectors
	inline bool	CheckBrick(int x,int y)
	{
		if(m_clppMyWalls[y][x].m_bActive)return true;
			else return false;
	}
	inline Brick* GetBrick(int x,int y){return &m_clppMyWalls[y][x];}

	//Used to put activators in the vectors
	// This one needs a lot of work
	inline bool CheckActivator(int Item)
	{
		COORD DIR = GetCoord((Directions)Item);
		if(m_clppMyObject[DIR.Y][DIR.X].m_bActive)return true;
			else return false;
	}
	inline BaseActivator* GetActivator(int Item)
	{
		COORD DIR;
		switch(Item)
		{
		case NORTH:
			DIR = getNorthCoord();
		case SOUTH:
			DIR = getSouthCoord();
		case EAST:
			DIR = getEastCoord();
		case WEST:
			DIR = getWestCoord();
		}
		return &m_clppMyObject[DIR.Y][DIR.X];
	}

	//Checks if the node has been visited
	inline bool wasVisited(){return m_bVisited;}
	
	//Sets whether the Node was visited or not
	inline void SetVisitState(bool V){m_bVisited = V;}

	//Checks if any of the directions are true
	// if they are it means movement in a direction is possible
	bool CanGoDirection();

	//Checks if the direction bool is true
	// Direction is an enum with all four directions
	bool CanGoDirection(Directions Direction);
	
	//Sets the directional Value to value given
	// Direction is an enum with all four directions
	void SetDirection(Directions Direction,bool D);

	//Returns the coordinates on the wall array of that node for that direction
	COORD getNorthCoord()
	{
		COORD N;
		N.X = 0;
		N.Y = 0;
		return N;
	}
	COORD getSouthCoord()
	{
		COORD S;
		S.X = 1;
		S.Y = 0;
		return S;
	}
	COORD getEastCoord()
	{
		COORD E;
		E.X = 1;
		E.Y = 1;
		return E;
	}
	COORD getWestCoord()
	{
		COORD W;
		W.X = 0;
		W.Y = 1;
		return W;
	}
	inline COORD GetCoord(Directions Direction)
	{
		switch(Direction)
		{
		case NORTH:
			return getNorthCoord();		
			break;
		case SOUTH:
			return getSouthCoord();
			break;
		case EAST:
			return getEastCoord();
			break;
		case WEST:
			return getWestCoord();
			break;
		}
		return COORD();
	}

	//Sets this directions wall to down
	// Also if the node is counted as not visited its
	// set to visited upon breaking a wall down
	void BreakWall(Directions Direction);

	//Makes this directions wall into a switch which owns a door
	void MakeButton(Directions Direction,int X,int Y);
	void MakeDoor(Directions Direction,int X, int Y);
};

	


	//TODO:	void SetStart();
	
	//TODO: void SetEnd();


	//TODO: Make these work
	//////Makes this directions wall into a door which is activated by
	//////corresponding switch
	////Door* MakeDoor(Directions Direction);


	